package com.amao.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @package : com.amao.controller
 * @Author : yongqi
 * @DATE : 2021/4/25 18:37
 * @描述 ：
 */
@Slf4j
@RestController
public class ClientController {

    @GetMapping("/get")
    @PreAuthorize("hasAnyRole('ROLE_USER')")
    public String get(Authentication authentication){
//        authentication.getCredentials();
        OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)authentication.getDetails();
        String token = details.getTokenValue();
        return "有权限的用户，token:"+token ;
    }
}
